package com.strive.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.strive.service.*;
import com.strive.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: strivePeng
 * @CreateTime: 2024年03月14日
 * @Description: 基础的controller类
 **/
public class BaseController {
    /**
     * 注入一些基础的Bean
     */
    @Autowired
    public HttpServletRequest req;

    @Autowired
    public RedisUtil redisUtil;

    @Autowired
    SysUserService sysUserService;

    @Autowired
    SysMenuService sysMenuService;

    @Autowired
    SysRoleService sysRoleService;

    @Autowired
    SysUserRoleService sysUserRoleService;

    @Autowired
    SysRoleMenuService sysRoleMenuService;

    /**
     * 获取页码
     *
     * @return 返回一个当 前页面 和 页码
     */
    public Page getPage() {
        /**
         * 设置一些默认值
         *
         * 获取前段传来的一些页码，和当前要查询多少条数据
         */
        int current = ServletRequestUtils.getIntParameter(req, "current", 1);
        int size = ServletRequestUtils.getIntParameter(req, "size", 10);

        return new Page(current, size);
    }

}
